package com.wd.health.view.activity.mine;

import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;

import com.wd.health.R;
import com.wd.health.model.adapter.HistoryWzAdapter;
import com.wd.health.model.bean.HistoryWzBean;
import com.wd.health.utils.RetrofitManager;

import java.util.List;

import io.reactivex.Observer;
import io.reactivex.disposables.Disposable;

public class HistoryWzActivity extends AppCompatActivity implements View.OnClickListener {

    private RecyclerView rv_historywz;
    private ImageView img_back;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_history_wz);
        initView();
        initData();
    }

    private void initData() {
        RetrofitManager.getInstance().getHistoryWzData(1, 10, new Observer<HistoryWzBean>() {
            @Override
            public void onSubscribe(Disposable d) {

            }

            @Override
            public void onNext(HistoryWzBean historyWzBean) {
                List<HistoryWzBean.ResultBean> list = historyWzBean.getResult();
                HistoryWzAdapter historyWzAdapter = new HistoryWzAdapter(list, getApplicationContext());
                rv_historywz.setAdapter(historyWzAdapter);
            }

            @Override
            public void onError(Throwable e) {

            }

            @Override
            public void onComplete() {

            }
        });
    }

    private void initView() {
        rv_historywz = findViewById(R.id.rv_historywz);
        img_back = findViewById(R.id.img_back);
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);
        rv_historywz.setLayoutManager(linearLayoutManager);
        img_back.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.img_back:
                finish();
                break;
        }
    }
}